package com.holyn.guofang.viewcommon.popupwindow;

import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.DecelerateInterpolator;

import com.holyn.guofang.R;

import razerdp.basepopup.BasePopupWindow;

/**
 * Created by Holyn on 2017/6/21.
 */

public class PopupResultListFilter extends BasePopupWindow implements View.OnClickListener{

    private OnFilterClickLIstener onFilterClickLIstener;

    public void setOnFilterClickLIstener(OnFilterClickLIstener onFilterClickLIstener) {
        this.onFilterClickLIstener = onFilterClickLIstener;
    }

    public interface OnFilterClickLIstener{
        public void onFilterClick(String SortType);
    }

    public PopupResultListFilter(Activity context) {
        super(context, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        findViewById(R.id.tv_sort_type_4).setOnClickListener(this);
        findViewById(R.id.tv_sort_type_5).setOnClickListener(this);
        findViewById(R.id.tv_sort_type_6).setOnClickListener(this);
        findViewById(R.id.tv_sort_type_7).setOnClickListener(this);
        findViewById(R.id.tv_sort_type_8).setOnClickListener(this);
    }

    @Override
    public View onCreatePopupView() {
        return createPopupById(R.layout.popup_result_list_filter);
    }

    @Override
    public View initAnimaView() {
        return getPopupWindowView().findViewById(R.id.popup_container);
    }

    @Override
    protected Animation initShowAnimation() {
        AnimationSet set = new AnimationSet(true);
        set.setInterpolator(new DecelerateInterpolator());
//        set.addAnimation(getScaleAnimation(0, 1, 0, 1, Animation.RELATIVE_TO_SELF, 1, Animation.RELATIVE_TO_SELF, 0));
        set.addAnimation(getTranslateAnimation(-200, 0, 300));
        set.addAnimation(getDefaultAlphaAnimation());
        return set;
//        return null;
    }

    @Override
    public View getClickToDismissView() {
        return null;
    }

    @Override
    public void showPopupWindow(View v) {
//        setOffsetX(-(getPopupViewWidth() - v.getWidth()));
        setOffsetX(0);
        setOffsetY(v.getHeight()+1);
        super.showPopupWindow(v);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.tv_sort_type_4:
                onFilterClickLIstener.onFilterClick("4");
                break;
            case R.id.tv_sort_type_5:
                onFilterClickLIstener.onFilterClick("5");
                break;
            case R.id.tv_sort_type_6:
                onFilterClickLIstener.onFilterClick("6");
                break;
            case R.id.tv_sort_type_7:
                onFilterClickLIstener.onFilterClick("7");
                break;
            case R.id.tv_sort_type_8:
                onFilterClickLIstener.onFilterClick("8");
                break;
        }
        PopupResultListFilter.this.dismiss();
    }
}
